#ifndef __GAME_THREAD_H__
#define __GAME_THREAD_H__


#include "game_config.h"
#include "game_def.h"


#if CGAME_TARGET_PLATFORM == CGAME_WIN
#define __INT64__ signed __int64
#define __UINT64__ unsigned __int64
#else

#include <pthread.h>

typedef pthread_t thread_t;
typedef pthread_cond_t cond_t;
typedef pthread_mutex_t mutex_t;



#endif

namespace CGame{
namespace Thread{
template <typename TYPE, void (TYPE::*run)() >  
void* __thread_run_cb(void* param)//线程启动函数，声明为模板函数  
{     
  TYPE* This = (TYPE*)param;     
  This->run();     
  return NULL;  
} 
}}

class CGameThread{
private:
  mutex_t _mutex;
  cond_t _cond;
protected:
  int cancel(thread_t t);
  void join(thread_t thread);
  void join();
  thread_t _thread;
public:
  CGameThread();
  ~CGameThread();
  virtual void run();
  void lock();
  void unlock();
  void sleep(mseconds_t ms);
  void wait();
  void signal();
  void broadcast();
  virtual thread_t start();
  virtual thread_t start(const char* name);
};


#endif
